********************************************************************************
********"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*****
********************************************************************************

********************************************************************************
********************************************************************************
**********************************2019******************************************
********************************************************************************
********************************************************************************
global y "lncdisbur_w199"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**#Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans2019, case(lower)
run RO_creditregister tm(2019m2) tm(2020m2) 0
keep bankid borrowerid time disbur

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2019, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2019m8, keepus(e10 e14 e13 e12 dtop66e14 dmid6633e14 exlnassets excashas)
keep if _merge==3
drop _merge

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2019, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2019m3)&time<=tm(2020m2)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)
run RO_tdummies 2019 12

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_CGP322019, keepus(cgasover)
keep if _merge!=2
drop _merge
recode cgasover (.=0)

gen count=1
bys bankid time: gen uniquebankidtime=sum(count)

foreach x of numlist 7 8 9 10 11 12 {
foreach var of varlist excashas exlnassets cgasover  {
gen dT`x'`var'=dT`x'*`var'
sum `var' if dT`x'==1&uniquebankidtime==1
gen dT`x'`var'sd=dT`x'`var'/r(sd)
}
}

keep $y dT*cgasoversd dT*exlnassets dT*excashas lncrefin bankid borrowerid time
reghdfe $y dT*cgasoversd dT*exlnassets dT*excashas lncrefin $regcommands
label variable dT7cgasoversd 2019m9
label variable dT8cgasoversd 2019m10
label variable dT9cgasoversd 2019m11
label variable dT10cgasoversd 2019m12
label variable dT11cgasoversd 2019m1
label variable dT12cgasoversd 2019m2

**#Bookmark (output)
graph drop _all
coefplot , keep(dT*cgasoversd) mcolor(black) ciopts(recast(rcap) col(black)) ytick(-5(2.5)5, tposition(inside) tlcolor(gs5)) ytitle("Growth rate of lending, percentage points") ylabel(-5(2.5)5, notick) yline(0, lcolor(gs5)) vertical xlabel(,angle(0)) levels(90) title("") graphregion(color(white) margin(zero)) saving($outputdirectory/FIG8A,replace)


********************************************************************************
********************************************************************************
**********************************2015******************************************
********************************************************************************
********************************************************************************
clear *
**#Bookmark (input)
global y "lncdisbur_w199"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**#Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**#Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(e10 e13 dtop85e13 exlnassets excashas)
keep if _merge==3
drop _merge

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

run RO_tdummies 2015 12

**#Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_CGP32015, keepus(cgasover)
keep if _merge!=2
drop _merge
recode cgasover (.=0)

gen count=1
bys bankid time: gen uniquebankidtime=sum(count)

foreach x of numlist 7 8 9 10 11 12 {
foreach var of varlist cgasover excashas exlnassets {
gen dT`x'`var'=dT`x'*`var'
sum `var' if dT`x'==1&uniquebankidtime==1
gen dT`x'`var'sd=dT`x'`var'/r(sd)
}
}

keep $y dT*cgasoversd dT*exlnassets dT*excashas lncrefin bankid borrowerid time
reghdfe $y dT*cgasoversd dT*exlnassets dT*excashas lncrefin $regcommands

label variable dT7cgasoversd 2015m1
label variable dT8cgasoversd 2015m2
label variable dT9cgasoversd 2015m3
label variable dT10cgasoversd 2015m4
label variable dT11cgasoversd 2015m5
label variable dT12cgasoversd 2015m6

**#Bookmark (output)
graph drop _all
coefplot, keep(dT*cgasoversd) mcolor(black) ciopts(recast(rcap) col(black)) ytick(-1.5(0.5)1.5, tposition(inside) tlcolor(gs5)) ytitle("Growth rate of lending, percentage points")ylabel(-1.5(0.5)1.5, notick) yline(0, lcolor(gs5)) vertical xlabel(,angle(0)) levels(90)   title("") graphregion(color(white) margin(zero)) saving($outputdirectory/FIG8B, replace)
